package com.timoon.webcomponent.utility.product.single.component;

import java.util.List;

import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.timoon.sample.dao.model.ProductComment;
import com.timoon.webcomponent.utility.product.BaseProductPanel;

/**
 *<p>评论列表</p>
 *<p></p>
 *<p>Copyright:Copyright(c)2013.4.1</p>
 *<p>Company:timoon</p>
 *@author 付乐天
 *@version 1.0 */
public class ProductCommentListPanel extends BaseProductPanel {

	@SpringBean(name="com.timoon.webcomponent.utility.product.service.ProductService")
	private ProductCommentListService service;
	
	private Integer productId;
	
	public ProductCommentListPanel(String id,Integer productId) {
		super(id);
		// TODO Auto-generated constructor stub
		
		this.productId=productId;
		
		renderPanel();
		
	}

	private void renderPanel() {
		// TODO Auto-generated method stub
		
		renderList();
	}

	@SuppressWarnings("serial")
	private void renderList() {
		// TODO Auto-generated method stub
		
		List<ProductComment> comments=this.service.getAllCommentByProductId(productId);
		
		ListView<ProductComment> listView=new ListView<ProductComment>("wk_list",comments) {
			
			@Override
			protected void populateItem(ListItem<ProductComment> arg0) {
				// TODO Auto-generated method stub
				ProductComment comment=arg0.getModelObject();
				
				arg0.add(new ProductSingleCommentPanel("wk_comment",comment));
			}
		};
		add(listView);
	}

	public ProductCommentListService getService() {
		return service;
	}

	public void setService(ProductCommentListService service) {
		this.service = service;
	}

}
